package com.renren.quick;

import org.apache.tomcat.util.codec.binary.Base64;

public class demo {
    private static final long salt = 0x785488ABC5874885L;

    public static String encode(Long id) {
        id = (id << 32 & 0xFFFFFFFF00000000L) | (id >> 32 & 0x00000000FFFFFFFFL);
        id ^= salt;
        return Base64.encodeBase64URLSafeString(id.toString().getBytes());
    }

    public static Long decode(String idStr) {
        idStr = new String(Base64.decodeBase64(idStr));
        Long id = Long.valueOf(idStr);
        id ^= salt;
        return (id << 32 & 0xFFFFFFFF00000000L) | (id >> 32 & 0x00000000FFFFFFFFL);
    }

    public static void main(String[] args) {
//        System.out.println(encode(7878910923750588L));
        System.out.println(decode("LTcwMjM1ODc4MTcxNTY3MjU0MTg"));
    }
}
